package com.xz.knowledgeDuplication.pattern.iterator;


import java.util.List;

/**
 * 具体迭代器角色
 *
 * @author 召
 * @date 2022-03-29 20:53:33
 */
public class IteratorImpl<T> implements Iterator<T> {

    private List<T> list;

    private int index = 0;

    public IteratorImpl(List<T> list) {
        this.list = list;
    }

    @Override
    public boolean hasNext() {
        return index < list.size();
    }

    @Override
    public T next() {
        T object = list.get(index);
        index++;
        return object;
    }
}
